package com.tools.web.filter.gateway;

import com.tools.common.io.CharsetEnum;
import com.tools.common.object.Note;
import com.tools.web.filter.cors.CorsSource;

import java.util.Objects;

/**
 * 网关配置项包装实例
 * */
@Note("网关配置项包装实例")
public final class GetawaySource {

    @Note("response 的 ContentType。默认为 JSON 字符串")
    private String responseContentType;

    @Note("response 的默认字符集。默认为 UTF-8")
    private CharsetEnum responseCharset;

    @Note("【代理服务器的 IP 白名单】 的 key。不为空则开启")
    private String proxyWhitesCacheKey;

    @Note("【接口禁用列表】 的 key。不为空则开启")
    private String disableURICacheKey;

    @Note("【客户端 IP 白名单】 - 的 key。不为空则开启")
    private String ipWhitesCacheKey;

    @Note("【客户端 IP 黑名单】 - 的 key。不为空则开启")
    private String ipBlacksCacheKey;

    @Note("【客户端 IP 黑名单】 功能启动后才生效。" +
            "这里是配置拉黑客户端 IP 的条件阈值等参数的包装类")
    private IPBlacksThreshold ipBlacksThreshold;

    @Note("初始化时读取进代理服务器 IP 白名单内的 IP。多个使用【,】分隔")
    private String proxyIPs;

    @Note("代理服务器 IP 的白名单文件路径，初始化时读取并放入白名单内。文件内一个 IP 需要占一行。")
    private String proxyIPsFilePath;

    @Note("初始化时读取进禁用接口列表内的接口。多个使用【,】分隔")
    private String disabledURIs;

    @Note("禁用接口列表的文件路径，初始化时读取并放入缓存列表内。文件内一个接口需要占一行。")
    private String disabledURIsFilePath;

    @Note("初始化时读取进客户端白名单内的客户端 IP。多个使用【,】分隔")
    private String whitesIps;

    @Note("客户端 IP 白名单的文件路径，初始化时读取并放入缓存列表内。文件内一个客户端 IP 需要占一行。")
    private String whitesIpsFilePath;

    @Note("初始化时读取进客户端黑名单内的客户端 IP。多个使用【,】分隔")
    private String blacksIps;

    @Note("客户端 IP 黑名单的文件路径，初始化时读取并放入缓存列表内。文件内一个客户端 IP 需要占一行。")
    private String blacksIpsFilePath;

    @Note("若网关要开启跨域配置，此处便是其中的配置项参数实体")
    private CorsSource corsSource;

    /* ********************************************************************************************
     *
     *         构造器
     *
     * *********************************************************************************************
     * */
    public GetawaySource() {}

    public static GetawaySource of() {
        return new GetawaySource();
    }

    /* ********************************************************************************************
     *
     *         Getter/Setter
     *
     * *********************************************************************************************
     * */

    public String getResponseContentType() {
        return responseContentType;
    }

    public void setResponseContentType(String responseContentType) {
        this.responseContentType = responseContentType;
    }

    public CharsetEnum getResponseCharset() {
        return responseCharset;
    }

    public void setResponseCharset(CharsetEnum responseCharset) {
        this.responseCharset = responseCharset;
    }

    public String getProxyWhitesCacheKey() {
        return proxyWhitesCacheKey;
    }

    public void setProxyWhitesCacheKey(String proxyWhitesCacheKey) {
        this.proxyWhitesCacheKey = proxyWhitesCacheKey;
    }

    public String getDisableURICacheKey() {
        return disableURICacheKey;
    }

    public void setDisableURICacheKey(String disableURICacheKey) {
        this.disableURICacheKey = disableURICacheKey;
    }

    public String getIpWhitesCacheKey() {
        return ipWhitesCacheKey;
    }

    public void setIpWhitesCacheKey(String ipWhitesCacheKey) {
        this.ipWhitesCacheKey = ipWhitesCacheKey;
    }

    public String getIpBlacksCacheKey() {
        return ipBlacksCacheKey;
    }

    public void setIpBlacksCacheKey(String ipBlacksCacheKey) {
        this.ipBlacksCacheKey = ipBlacksCacheKey;
    }

    public IPBlacksThreshold getIpBlacksThreshold() {
        return ipBlacksThreshold;
    }

    public void setIpBlacksThreshold(IPBlacksThreshold ipBlacksThreshold) {
        this.ipBlacksThreshold = ipBlacksThreshold;
    }

    public String getProxyIPs() {
        return proxyIPs;
    }

    public void setProxyIPs(String proxyIPs) {
        this.proxyIPs = proxyIPs;
    }

    public String getProxyIPsFilePath() {
        return proxyIPsFilePath;
    }

    public void setProxyIPsFilePath(String proxyIPsFilePath) {
        this.proxyIPsFilePath = proxyIPsFilePath;
    }

    public String getDisabledURIs() {
        return disabledURIs;
    }

    public void setDisabledURIs(String disabledURIs) {
        this.disabledURIs = disabledURIs;
    }

    public String getDisabledURIsFilePath() {
        return disabledURIsFilePath;
    }

    public void setDisabledURIsFilePath(String disabledURIsFilePath) {
        this.disabledURIsFilePath = disabledURIsFilePath;
    }

    public String getWhitesIps() {
        return whitesIps;
    }

    public void setWhitesIps(String whitesIps) {
        this.whitesIps = whitesIps;
    }

    public String getWhitesIpsFilePath() {
        return whitesIpsFilePath;
    }

    public void setWhitesIpsFilePath(String whitesIpsFilePath) {
        this.whitesIpsFilePath = whitesIpsFilePath;
    }

    public String getBlacksIps() {
        return blacksIps;
    }

    public void setBlacksIps(String blacksIps) {
        this.blacksIps = blacksIps;
    }

    public String getBlacksIpsFilePath() {
        return blacksIpsFilePath;
    }

    public void setBlacksIpsFilePath(String blacksIpsFilePath) {
        this.blacksIpsFilePath = blacksIpsFilePath;
    }

    public CorsSource getCorsSource() {
        return corsSource;
    }

    public void setCorsSource(CorsSource corsSource) {
        this.corsSource = corsSource;
    }

    @Override
    public String toString() {
        return "GetawaySource{" +
                "responseContentType='" + responseContentType + '\'' +
                ", responseCharset=" + responseCharset +
                ", proxyWhitesCacheKey='" + proxyWhitesCacheKey + '\'' +
                ", disableURICacheKey='" + disableURICacheKey + '\'' +
                ", ipWhitesCacheKey='" + ipWhitesCacheKey + '\'' +
                ", ipBlacksCacheKey='" + ipBlacksCacheKey + '\'' +
                ", ipBlacksThreshold=" + ipBlacksThreshold +
                ", proxyIPs='" + proxyIPs + '\'' +
                ", proxyIPsFilePath='" + proxyIPsFilePath + '\'' +
                ", disabledURIs='" + disabledURIs + '\'' +
                ", disabledURIsFilePath='" + disabledURIsFilePath + '\'' +
                ", whitesIps='" + whitesIps + '\'' +
                ", whitesIpsFilePath='" + whitesIpsFilePath + '\'' +
                ", blacksIps='" + blacksIps + '\'' +
                ", blacksIpsFilePath='" + blacksIpsFilePath + '\'' +
                ", corsSource=" + corsSource +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        GetawaySource that = (GetawaySource) o;
        return Objects.equals(responseContentType, that.responseContentType) && responseCharset == that.responseCharset && Objects.equals(proxyWhitesCacheKey, that.proxyWhitesCacheKey) && Objects.equals(disableURICacheKey, that.disableURICacheKey) && Objects.equals(ipWhitesCacheKey, that.ipWhitesCacheKey) && Objects.equals(ipBlacksCacheKey, that.ipBlacksCacheKey) && Objects.equals(ipBlacksThreshold, that.ipBlacksThreshold) && Objects.equals(proxyIPs, that.proxyIPs) && Objects.equals(proxyIPsFilePath, that.proxyIPsFilePath) && Objects.equals(disabledURIs, that.disabledURIs) && Objects.equals(disabledURIsFilePath, that.disabledURIsFilePath) && Objects.equals(whitesIps, that.whitesIps) && Objects.equals(whitesIpsFilePath, that.whitesIpsFilePath) && Objects.equals(blacksIps, that.blacksIps) && Objects.equals(blacksIpsFilePath, that.blacksIpsFilePath) && Objects.equals(corsSource, that.corsSource);
    }

    @Override
    public int hashCode() {
        return Objects.hash(responseContentType, responseCharset, proxyWhitesCacheKey, disableURICacheKey, ipWhitesCacheKey, ipBlacksCacheKey, ipBlacksThreshold, proxyIPs, proxyIPsFilePath, disabledURIs, disabledURIsFilePath, whitesIps, whitesIpsFilePath, blacksIps, blacksIpsFilePath, corsSource);
    }

    /* ********************************************************************************************
     *
     *         链式调用
     *
     * *********************************************************************************************
     * */

    public GetawaySource responseContentType(String responseContentType) {
        this.setResponseContentType(responseContentType);
        return this;
    }

    public GetawaySource responseCharset(CharsetEnum responseCharset) {
        this.setResponseCharset(responseCharset);
        return this;
    }

    public GetawaySource proxyWhitesCacheKey(String proxyWhitesCacheKey) {
        this.setProxyWhitesCacheKey(proxyWhitesCacheKey);
        return this;
    }

    public GetawaySource disableURICacheKey(String disableURICacheKey) {
        this.setDisableURICacheKey(disableURICacheKey);
        return this;
    }

    public GetawaySource ipWhitesCacheKey(String ipWhitesCacheKey) {
        this.setIpWhitesCacheKey(ipWhitesCacheKey);
        return this;
    }

    public GetawaySource ipBlacksCacheKey(String ipBlacksCacheKey) {
        this.setIpBlacksCacheKey(ipBlacksCacheKey);
        return this;
    }

    public GetawaySource ipBlacksThreshold(IPBlacksThreshold ipBlacksThreshold) {
        this.setIpBlacksThreshold(ipBlacksThreshold);
        return this;
    }

    public GetawaySource proxyIPs(String proxyIPs) {
        this.setProxyIPs(proxyIPs);
        return this;
    }

    public GetawaySource proxyIPsFilePath(String proxyIPsFilePath) {
        this.setProxyIPsFilePath(proxyIPsFilePath);
        return this;
    }

    public GetawaySource disabledURIs(String disabledURIs) {
        this.setDisabledURIs(disabledURIs);
        return this;
    }

    public GetawaySource disabledURIsFilePath(String disabledURIsFilePath) {
        this.setDisabledURIsFilePath(disabledURIsFilePath);
        return this;
    }

    public GetawaySource blacksIps(String blacksIps) {
        this.setBlacksIps(blacksIps);
        return this;
    }

    public GetawaySource blacksIpsFilePath(String blacksIpsFilePath) {
        this.setBlacksIpsFilePath(blacksIpsFilePath);
        return this;
    }

    public GetawaySource whitesIps(String whitesIps) {
        this.setWhitesIps(whitesIps);
        return this;
    }

    public GetawaySource whitesIpsFilePath(String whitesIpsFilePath) {
        this.setWhitesIpsFilePath(whitesIpsFilePath);
        return this;
    }

    public GetawaySource corsSource(CorsSource corsSource) {
        this.setCorsSource(corsSource);
        return this;
    }
}
